package net.bwie.realtime.jtp.function;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.flink.api.common.functions.RichMapFunction;
import org.apache.flink.configuration.Configuration;

import java.util.HashMap;

/**
 * 简介说明:
 *
 * @author: LiLi
 * @date: 2025/06/02 22:08:26
 * @version: 1.0
 */
public class HbaseDimMapFunction extends RichMapFunction<String,String> {
    private HashMap<String,String> dimMap;

    public HbaseDimMapFunction(HashMap<String, String> dimMap) {
        this.dimMap = dimMap;
    }

    @Override
    public void open(Configuration parameters) throws Exception {
        super.open(parameters);
    }

    @Override
    public String map(String s) throws Exception {

        // a. 解析json
        JSONObject jsonObject = JSON.parseObject(s);

// b. 添加字段--hbase表名称
        jsonObject.put("hbase_table_name", "dim_" + jsonObject.getString("table_name"));

// b. 添加字段--列簇名称
        jsonObject.put("family_name", "info");

// b. 添加字段--rowKey值对应字段名称
        jsonObject.put("row_key_column", dimMap.get(jsonObject.getString("table_name")));

// c. 返回json
        return jsonObject.toJSONString();
    }

    @Override
    public void close() throws Exception {
        super.close();
    }
}
